package com.feige.controller;


import com.feige.pojo.Collect;
import com.feige.service.CollectService;
import com.feige.result.AjaxResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 * 收藏表 前端控制器
 * </p>
 *
 * @author feige
 * @since 2021-04-05
 */
@Api(tags = "收藏表 前端控制器")
@RestController
@RequestMapping("/courseware/collect")
public class CollectController {

    @Resource
    private CollectService collectService;

    @ApiOperation(value = "保存收藏")
    @PostMapping("/save")
    public AjaxResult save(@RequestBody Collect collect){
        boolean save = collectService.save(collect);
        if (save){
            return AjaxResult.success();
        }else {
            return AjaxResult.error();
        }
    }

    @ApiOperation(value = "获取收藏")
    @GetMapping("/{pageNum}/{userId}")
    public AjaxResult get(
            @PathVariable Integer pageNum,
            @PathVariable String userId
    ){
        return collectService.getCollectByUserId(pageNum,userId);
    }

    @ApiOperation(value = "删除收藏")
    @DeleteMapping("/delete/{id}")
    public AjaxResult delete(@PathVariable String id){
        boolean delete = collectService.removeById(id);
        if (delete){
            return AjaxResult.success();
        }else {
            return AjaxResult.error();
        }
    }
}

